#! encoding=utf-8

import requests
import traceback
from common import HOST


def analyze(image):
    url = HOST + '/analyze'
    print "POST /analyze 人脸属性分析 ..."
    ret = None
    try:
        ret = requests.session().post(url, files={'image': ('filename.jpg', open(image, 'rb'))}).content
    except:
        print traceback.format_exc()
    print ret


def compare(image_1, image_2):
    url = HOST + '/compare'
    print "POST /compare 人脸比对 ..."
    ret = None
    try:
        ret = requests.session().post(url, files={'image_1': ('filename1.jpg', open(image_1, 'rb')), 'image_2': ('filename2.jpg', open(image_2, 'rb'))}).content
    except:
        print traceback.format_exc()
    print ret



def recognize(group_id, image, check_quality, limit):
    url = HOST + '/recognize'
    print "POST /recognize 静态识别 ..."
    ret = None
    try:
        ret = requests.session().post(url, {'group_id': group_id, 'check_quality': 'true', 'limit': limit}, files={'image': ('filename.jpg', open(image, 'rb'))}).content
    except:
        print traceback.format_exc()
    print ret



def verify(group_id, user_id, image, check_quality):
    url = HOST + '/verify'
    print "POST /verify 静态单人比对 ..."
    ret = None
    try:
        ret = requests.session().post(url, {'group_id': group_id, 'check_quality': 'true', 'user_id': user_id}, files={'image': ('filename.jpg', open(image, 'rb'))}).content
    except:
        print traceback.format_exc()
    print ret